package labs.laba_03;

import java.math.BigDecimal;
import java.util.ArrayList;

import android.graphics.Canvas;
import android.graphics.Paint;

public class FRectangle extends Figure {

	public FRectangle(float center_x, float center_y, Figure parent, FigureTypes ft){
		super(center_x, center_y, parent, ft);
	}
	private Dot[] getDots() {
		Dot dts[] = new Dot[2];
		float halfwidth = BigDecimal.valueOf(width/2).setScale(3).floatValue();
		dts[0] = new Dot(this.center.getX()-halfwidth,	this.center.getY()-halfwidth);
		dts[1] = new Dot(this.center.getX()+halfwidth,	this.center.getY()+halfwidth);
		return dts;
	}
	@Override
	public float getOuterRadius() {
		return (float)Math.sqrt(Math.pow((width/2), 2)+Math.pow((width/2), 2));
	}
	@Override
	public ArrayList<PrimitiveLine> getPrimitive() {
		Dot dots[] = getDots();
		ArrayList<PrimitiveLine> pl_list = new ArrayList<PrimitiveLine>(3);
		pl_list.add(new PrimitiveLine(new Dot(dots[0].getX(), dots[1].getY()),	dots[0]));
		pl_list.add(new PrimitiveLine(dots[0],	new Dot(dots[1].getX(), dots[0].getY())));
		pl_list.add(new PrimitiveLine(new Dot(dots[1].getX(), dots[0].getY()),	dots[1]));
		pl_list.add(new PrimitiveLine(dots[1],	new Dot(dots[0].getX(), dots[1].getY())));
		return pl_list;
	}
	@Override
	public void draw(Canvas canvas) {
		Dot dots[] = getDots();
		Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);            
		mPaint.setStrokeWidth(2);
		//paint.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
		mPaint.setARGB(255, 200, 100, 50);
		mPaint.setStyle(Paint.Style.FILL);
		//mPaint.setAntiAlias(true);
		canvas.drawRect(dots[0].getX(), dots[0].getY(), dots[1].getX(), dots[1].getY(), mPaint);
	}
}
